n=input()
if len(n) !=4 or not n.isdigit():
    print(0)
else:
    def f(n):
        for i in range(2,int(n**0.5)+1):
            if n%i == 0:
                return False
        return True
   
    m= [0]
    for i in range(4):
        a=n[i]
        if f(int(a)):
            m.append(int(a))
        for j in range(i+1,4):
            a+=n[j]
            if f(int(a)):
                m.append(int(a))
    print(max(m))
